package org.eking.bigdata.spark;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.spark.sql.Row;
import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.tools.internal.jxc.gen.config.Schema;

import scala.collection.Seq;

public class TestRow implements Row {
	
	private ArrayList<RowContect> RowItem;
	private static StructType schema ;
	 static final Logger logger = LoggerFactory.getLogger(TestRow.class);
	 
	public TestRow(){
		RowItem = new ArrayList();
	}
	
	public void SetStructTypes(List<StructField> fields){
		schema = DataTypes.createStructType(fields);
	}
	
	public void AppendColume(String Name, Object Value) throws Exception{
		
		if(schema == null){
			logger.error("schema is null exception");
			throw new Exception();
		}
		
		int Pos = schema.fieldIndex(Name);
		
		RowContect row = new RowContect();
		if(Value == null){
			row.IsNull = true;
			row.value = null;
		}else{
			row.value = Value;
			row.IsNull = false;
		}
		row.RowPos = Pos;
		RowItem.add(row);
				
	}
	
	@Override
	public boolean anyNull() {
		// TODO Auto-generated method stub
		for(RowContect rw : RowItem){
			if(rw.IsNull == true)
				return true;
		}
		return false;
	}

	@Override
	public Object apply(int idx) {
		// TODO Auto-generated method stub
		return RowItem.get(idx).value;
	}

	@Override
	public Row copy() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int fieldIndex(String FieldName) {
		// TODO Auto-generated method stub
		return 0;
		
	}

	@Override
	public Object get(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T getAs(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T getAs(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean getBoolean(int arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public byte getByte(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Date getDate(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BigDecimal getDecimal(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public double getDouble(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public float getFloat(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getInt(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public <K, V> Map<K, V> getJavaMap(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> List<T> getList(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getLong(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public <K, V> scala.collection.Map<K, V> getMap(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> Seq<T> getSeq(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public short getShort(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getString(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Row getStruct(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Timestamp getTimestamp(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> scala.collection.immutable.Map<String, T> getValuesMap(Seq<String> arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isNullAt(int arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int length() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String mkString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String mkString(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String mkString(String arg0, String arg1, String arg2) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public StructType schema() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Seq<Object> toSeq() {
		// TODO Auto-generated method stub
		return null;
	}

}
